package com.x.epspace.ext;

import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

@Service("handleSession")
public class HandleSessionService {
	
	public boolean setVal(String key,Object value){
		RequestAttributes ra = RequestContextHolder.currentRequestAttributes();
		if(ra == null) return false;
		ra.setAttribute(key,value,RequestAttributes.SCOPE_SESSION);
		return true;
	}
	
	public Object getVal(String key){
		RequestAttributes ra = RequestContextHolder.currentRequestAttributes();
		if(ra == null) return null;
		return ra.getAttribute(key,RequestAttributes.SCOPE_SESSION);
	}
	
	public void removeVal(String key){
		RequestAttributes ra = RequestContextHolder.currentRequestAttributes();
		if(ra == null) return;
		ra.removeAttribute(key, RequestAttributes.SCOPE_SESSION);
	}
	
}
